﻿// Inner Fire 游戏引擎库
// 光源类
//
// Copyright (c) 2024 by 尔西大帝. All rights reserved.
//
// 处理光源相关的信息
//
// Author: 尔西大帝
// Email: 2670613871@qq.com
// Created: 2024-12-02

#include "light.h"
#include <enum_parser.h>

namespace ifire::dx {

static LightType ParseLightType(ikit::sstr name) {
  static std::pair<ikit::sstr, LightType> enums[] = {
      {"Directional", LightType::Directional}, //
      {"Point", LightType::Point},             //
      {"Spot", LightType::Spot}                //
  };
  static ikit::EnumParser<LightType> parser(enums, (int)LightType::Spot + 1);
  return parser.Get(name, LightType::Directional);
}

LightSetting::LightSetting(const ikit::XmlNode& node, int index) {
  light.color = node("Color");
  light.direction = node("Direction");
  auto& pos = node("Position");
  light.position = pos;
  light.falloff_start = 1.0;
  light.falloff_end = node("Range");
  light.spot_power = node("SpotPower");
  disable = node("Disable");
  type = ParseLightType(node("Type"));
}

} // namespace ifire::dx